<!--
 * @Description: 
 * @Author: charles
 * @Date: 2020-11-03 14:05:02
 * @LastEditors: charles
 * @LastEditTime: 2021-08-01 14:07:59
-->
<template>
  <div>
    <div class="article">
      <div class="wrapper">
        <!-- 文章内容开始 -->
        <div class="title">{{ article.title }}</div>
        <div class="time">
          {{ article.publishTime | fmtDate }} | {{ article.baseUser.realname }}
        </div>
        <div class="wrapper" v-html="article.content"></div>
        <!-- 文章内容结束 -->
        <!-- 点赞按钮开始 -->
        <div class="zan-btn">
          <el-button size="small" @click="prise()">点赞</el-button>
        </div>
        <!-- 点赞按钮结束 -->
      </div>
    </div>
  </div>
</template>

<script>
import { get } from "../utils/request";
export default {
  data() {
    return {
      id: this.$route.query.id,
      article: "",
    };
  },
  methods: {
    // 获取文章信息
    async getArticleDetail() {
      const data = {
        id: this.id,
      };
      await get("/index/article/findById", data).then((res) => {
        this.article = res.data;
        console.log(this.article);
      });
    },
    // 点赞
    prise(){
      get('/index/article/thumbUp?id='+ this.id).then(res =>{
        console.log(res);
        if(res.status === 200){
          this.$message({
            type:'success',
            message:res.message
          })
        }else{
          this.$message({
            type:'error',
            message:res.message
          })
        }
      })
    }
  },
  created() {
    this.getArticleDetail();
  },
};
</script>
<style lang="scss" scoped>
.article {
  width: 980px;
  margin: 0 auto;
  .wrapper {
    .title {
      font-size: 20px;
      color: #000;
      font-weight: 700;
      text-align: center;
      padding: 1em 0;
    }
    .time {
      text-align: center;
    }
    .zan-btn {
      width: 200px;
      margin: 0 auto;
      padding: 1em 0;
    }
  }
}
</style>